<% layout("/layouts/micro.html"){ %>
<div class="layui-fluid">
	<div class="layui-card">
 <!--<div class="layui-tab layui-tab-brief childrenBody">
      <ul class="layui-tab-title">
         <li class="layui-this"><a href="${ctx}/sys/role/">角色列表</a></li>
         <%if(shiro.hasPermission("sys:role:edit")){%>
			 <li><a href="${ctx}/sys/role/form">角色添加</a></li>
		 <%}%>
      </ul>
  	<div class="layui-tab-content">-->
		<div class="layui-card-body">
			<#message content="${message!}"/>
			<%if(shiro.hasPermission("sys:role:edit")){%>
			<div>
				<button class="layui-btn layui-btn-normal LAY_ADD_role_btn"><i class="layui-icon layui-icon-add-1"></i>角色添加</button>
			</div>
			<%}%>
			<table class="layui-table" >
				<thead>
				<tr><th>角色名称</th><th>英文名称</th><th>归属机构</th><th>数据范围</th><%if(shiro.hasPermission("sys:role:edit")){%><th width="170px">操作</th><%}%></tr>
				</thead>
					<%for(role in list){%>
					<tr>
						<td>${role.name}</td>
						<td>${role.enname}</td>
						<td>${role.office.name}</td>
						<td>${@DictUtils.getDictLabel(role.dataScope, 'sys_data_scope', '无')}</td>
						<%if(shiro.hasPermission("sys:role:edit")){%>
						<td>
							<a class="layui-btn layui-btn-xs" onclick="roleAssign('${role.id}')" href="javascript:void(0);">分配</a>
							<%
								var flag = @DictUtils.getDictValue('是', 'yes_no', '1');
								var user = @UserUtils.getUser();
								if((role.sysData==flag && user.admin)||(role.sysData!=flag)){
							%>
								<a class="layui-btn layui-btn-xs" onclick="editRole('${role.id}')" href="javascript:void(0);">修改</a>
							<%}%>
							<a class="layui-btn layui-btn-xs layui-btn-danger " href="${ctx}/sys/role/delete?id=${role.id}" onclick="return confirmx('确认要删除该角色吗？', this.href)">删除</a>
						</td>
						<%}%>
					</tr>
					<%}%>
			</table>
		</div>
	</div>
</div>
<script>
    layui.use(['form','layer'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        //添加
        $(".LAY_ADD_role_btn").click(function(){
            var index = layui.layer.open({
                title : "添加角色",
                type : 2,
                content : "${ctx}/sys/role/form",
                area: ['100%', '100%'],
                btn: ['确定', '取消'],
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find('#roleForm');
                    submit.trigger('click');
                    layer.close(index);
                },
                end:function(){
                    location.reload();
                }
            })
        })
    })
    var editRole = function(id){
        var index = layui.layer.open({
            title : "修改角色",
            type : 2,
            content : "${ctx}/sys/role/form?id="+id,
            area: ['100%', '100%'],
            btn: ['确定', '取消'],
            yes: function(index, layero){
                var submit = layero.find('iframe').contents().find('#roleForm');
                submit.trigger('click');
                layer.close(index);
            },
            end:function(){
                location.reload();
            }
        })
    }
    var roleAssign = function(id){
        var index = layui.layer.open({
            title : "分配角色",
            type : 2,
            content : "${ctx}/sys/role/assign?id="+id,
            area: ['1000px', '800px'],
            btn: ['取消']
        })
    }
</script>
<%}%>